<?php
require_once(APPPATH . '/controllers/test/Toast.php');

//index declarations
$_POST['student_number']='';
$_POST['first_name']='';
$_POST['middle_name']='';
$_POST['last_name']='';
$_POST['gender']='';
$_POST['civil_status']='';
$_POST['birthday']='';
$_POST['religion']='';
$_POST['course']='';
$_POST['college']='';
$_POST['classification']='';
$_POST['home_address']='';
$_POST['telephone_number']='';
$_POST['email_address']='';
$_POST['region']='';
$_POST['name_of_father']='';
$_POST['telnumber_of_father']='';
$_POST['name_of_mother']='';
$_POST['telnumber_of_mother']='';
$_POST['name_of_guardian']='';
$_POST['telnumber_of_guardian']='';
$_POST['control_number']='';
$_POST['type_of_appliance']='';
$_POST['choice']='';
$_POST['date_installed']='';
$_POST['date_cancelled']='';
$_POST['remark']='';
$_POST['or_number']='';
$_POST['from_period']='';
$_POST['to_period']='';
$_POST['type']='';
$_POST['amount']='';
$_POST['date_paid']='';

class Unit_tests extends Toast
{
	function Unit_tests()
	{
		parent::Toast(__FILE__);
		// Load any models, libraries etc. you need here
	}

	/**
	 * OPTIONAL; Anything in this function will be run before each test
	 * Good for doing cleanup: resetting sessions, renewing objects, etc.
	 */
	function _pre() {}

	/**
	 * OPTIONAL; Anything in this function will be run after each test
	 * I use it for setting $this->message = $this->My_model->getError();
	 */
	function _post() {}


	/* TESTS BELOW */
	
	/* For Resident */
	function test_addResidentThatPass()
	{
		$this->message='Adds a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->_assert_equals($this->Resident_model->check_resident($_POST),1);
	}
	
	function test_editResidentThatPass()
	{
		$this->message='Edits a Resident';
		$_POST['student_number']='0000-00000';
		$_POST['first_name']='test_name';
		$this->load->model('Resident_model');
		$this->Resident_model->edit_resident($_POST);
		$query = $this->Resident_model->get_resident($_POST);
		$row = $query->row();
		$this->_assert_equals($row->first_name,'test_name');
	}
	
	function test_checkResidentThatPass()
	{
		$this->message='Checks a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$this->_assert_equals($this->Resident_model->check_resident($_POST),1);
	}
	
	function test_getResidentThatPass()
	{
		$this->message='Gets a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$query = $this->Resident_model->get_resident($_POST);
		$row = $query->row();
		$this->_assert_equals($row->first_name,'test_name');
	}
	
	function test_deleteResidentThatPass()
	{
		$this->message='Deletes a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$this->Resident_model->delete_resident($_POST);
		$this->_assert_equals($this->Resident_model->check_resident($_POST),0);
	}
	
	function test_addResidentThatFails()
	{
		$this->message='Adds a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		if($this->Resident_model->check_resident($_POST)==0){
			$this->Resident_model->add_resident($_POST);
			$this->_assert_equals($this->Resident_model->check_resident($_POST),1);
		}else{
			$this->_assert_equals($this->Resident_model->check_resident($_POST),0);
		}
	}
	
	function test_editResidentThatFails()
	{
		$this->message='Edits a Resident';
		$_POST['student_number']='0000-00001';
		$_POST['first_name']='test_name';
		$this->load->model('Resident_model');
		if($this->Resident_model->check_resident($_POST)==0){
			$this->_assert_equals($this->Resident_model->check_resident($_POST),1);
		}else{
			$this->Resident_model->edit_resident($_POST);
			$query = $this->Resident_model->get_resident($_POST);
			$row = $query->row();
			$this->_assert_equals($row->first_name,'test_name');
		}
	}
	
	function test_checkResidentThatFails()
	{
		$this->message='Checks a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$this->_assert_equals($this->Resident_model->check_resident($_POST),0);
	}
	
	function test_getResidentThatFails()
	{
		$this->message='Gets a Resident';
		$_POST['student_number']='0000-00000';
		$this->load->model('Resident_model');
		$query = $this->Resident_model->get_resident($_POST);
		$row = $query->row();
		$this->_assert_equals($row->first_name,'');
	}
	
	function test_deleteResidentThatFails()
	{
		$this->message='Deletes a Resident';
		$_POST['student_number']='0000-00001';
		$this->load->model('Resident_model');
		if($this->Resident_model->check_resident($_POST)==0){
			$this->_assert_equals($this->Resident_model->check_resident($_POST),1);
		}else{
			$this->Resident_model->delete_resident($_POST);
			$this->_assert_equals($this->Resident_model->check_resident($_POST),0);
		}
		$_POST['student_number']='0000-00000';
		$this->Resident_model->delete_resident($_POST);
	}
	
	/* For Appliance */
	function test_addApplianceThatPass()
	{
		$this->message='Adds an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$this->Appliance_model->add_appliance($_POST);
		$this->_assert_equals($this->Appliance_model->check_appliance($_POST),1);
	}
	
	function test_editApplianceThatPass()
	{
		$this->message='Edits an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$_POST['type_of_appliance']='test_app';
		$this->load->model('Appliance_model');
		$this->Appliance_model->edit_appliance($_POST);
		$query = $this->Appliance_model->get_appliance($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type_of_appliance,'test_app');
	}
	
	function test_checkApplianceThatPass()
	{
		$this->message='Checks an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$this->_assert_equals($this->Appliance_model->check_appliance($_POST),1);
	}
	
	function test_getApplianceThatPass()
	{
		$this->message='Gets an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$query = $this->Appliance_model->get_appliance($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type_of_appliance,'test_app');
	}
	
	function test_getAppliancesThatPass()
	{
		$this->message='Gets all Appliances';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$query = $this->Appliance_model->get_appliances($_POST);
		$row = $query->num_rows();
		$this->_assert_equals($row,1);
	}
	
	function test_deleteApplianceThatPass()
	{
		$this->message='Deletes an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['choice']='00000';
		$this->load->model('Appliance_model');
		$this->Appliance_model->delete_appliance($_POST);
		$this->_assert_equals($this->Appliance_model->check_appliance($_POST),0);
	}
	
	function test_addApplianceThatFails()
	{
		$this->message='Adds an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$this->Appliance_model->add_appliance($_POST);
		if($this->Appliance_model->check_appliance($_POST)==0){
			$this->Appliance_model->add_appliance($_POST);
			$this->_assert_equals($this->Appliance_model->check_appliance($_POST),1);
		}else{
			$this->_assert_equals($this->Appliance_model->check_appliance($_POST),0);
		}
	}
	
	function test_editApplianceThatFails()
	{
		$this->message='Edits an Appliance';
		$_POST['student_number']='0000-00001';
		$_POST['control_number']='00000';
		$_POST['type_of_appliance']='test_app';
		$this->load->model('Appliance_model');
		if($this->Appliance_model->check_appliance($_POST)==0){
			$this->_assert_equals($this->Appliance_model->check_appliance($_POST),1);
		}else{
			$this->Appliance_model->edit_appliance($_POST);
			$query = $this->Appliance_model->get_appliance($_POST);
			$row = $query->row();
			$this->_assert_equals($row->type_of_appliance,'test_app');
		}
	}
	
	function test_checkApplianceThatFails()
	{
		$this->message='Checks an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$this->_assert_equals($this->Appliance_model->check_appliance($_POST),0);
	}
	
	function test_getApplianceThatFails()
	{
		$this->message='Gets an Appliance';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$query = $this->Appliance_model->get_appliance($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type_of_appliance,'');
	}
	
	function test_getAppliancesThatFails()
	{
		$this->message='Gets all Appliances';
		$_POST['student_number']='0000-00000';
		$_POST['control_number']='00000';
		$this->load->model('Appliance_model');
		$query = $this->Appliance_model->get_appliances($_POST);
		$row = $query->num_rows();
		$this->_assert_equals($row,2);
	}
	
	function test_deleteApplianceThatFails()
	{
		$this->message='Deletes an Appliance';
		$_POST['student_number']='0000-00001';
		$_POST['choice']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Appliance_model');
		if($this->Appliance_model->check_appliance($_POST)==0){
			$this->_assert_equals($this->Appliance_model->check_appliance($_POST),1);
		}else{
			$this->Appliance_model->delete_appliance($_POST);
			$this->_assert_equals($this->Appliance_model->check_appliance($_POST),0);
		}
		$_POST['student_number']='0000-00000';
		$_POST['choice']='00000';
		$this->Appliance_model->delete_appliance($_POST);
	}
	
	/* For Payment */
	function test_addPaymentThatPass()
	{
		$this->message='Adds a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$this->Payment_model->add_payment($_POST);
		$this->_assert_equals($this->Payment_model->check_payment($_POST),1);
	}
	
	function test_editPaymentThatPass()
	{
		$this->message='Edits a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$this->Payment_model->edit_payment($_POST);
		$query = $this->Payment_model->get_payment($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type,'test_pay');
	}
	
	function test_checkPaymentThatPass()
	{
		$this->message='Checks a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$this->_assert_equals($this->Payment_model->check_payment($_POST),1);
	}
	
	function test_getPaymentThatPass()
	{
		$this->message='Gets a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$query = $this->Payment_model->get_payment($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type,'test_pay');
	}
	
	function test_getPaymentsThatPass()
	{
		$this->message='Gets all Payments';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$query = $this->Payment_model->get_payments($_POST);
		$row = $query->num_rows();
		$this->_assert_equals($row,1);
	}
	
	function test_deletePaymentThatPass()
	{
		$this->message='Deletes a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['choice']='00000';
		$_POST['type_hidden']='test_pay';
		$this->load->model('Payment_model');
		$this->Payment_model->delete_payment($_POST);
		$this->_assert_equals($this->Payment_model->check_payment($_POST),0);
	}
	
	function test_addPaymentThatFails()
	{
		$this->message='Adds a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$this->Payment_model->add_payment($_POST);
		if($this->Payment_model->check_payment($_POST)==0){
			$this->Payment_model->add_payment($_POST);
			$this->_assert_equals($this->Payment_model->check_payment($_POST),1);
		}else{
			$this->_assert_equals($this->Payment_model->check_payment($_POST),0);
		}
	}
	
	function test_editPaymentThatFails()
	{
		$this->message='Edits a Payment';
		$_POST['student_number']='0000-00001';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		if($this->Payment_model->check_payment($_POST)==0){
			$this->_assert_equals($this->Payment_model->check_payment($_POST),1);
		}else{
			$this->Payment_model->edit_payment($_POST);
			$query = $this->Payment_model->get_payment($_POST);
			$row = $query->row();
			$this->_assert_equals($row->type,'test_pay');
		}
	}
	
	function test_checkPaymentThatFails()
	{
		$this->message='Checks a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type_hidden']='test_pay';
		$this->load->model('Payment_model');
		$this->_assert_equals($this->Payment_model->check_payment($_POST),0);
	}
	
	function test_getPaymentThatFails()
	{
		$this->message='Gets a Payment';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type_hidden']='test_pay';
		$this->load->model('Payment_model');
		$query = $this->Payment_model->get_payment($_POST);
		$row = $query->row();
		$this->_assert_equals($row->type,'');
	}
	
	function test_getPaymentsThatFails()
	{
		$this->message='Gets all Payments';
		$_POST['student_number']='0000-00000';
		$_POST['or_number']='00000';
		$_POST['type']='test_pay';
		$this->load->model('Payment_model');
		$query = $this->Payment_model->get_payments($_POST);
		$row = $query->num_rows();
		$this->_assert_equals($row,2);
	}
	
	function test_deletePaymentThatFails()
	{
		$this->message='Deletes a Payment';
		$_POST['student_number']='0000-00001';
		$_POST['choice']='00000';
		$_POST['type_hidden']='test_pay';
		$this->load->model('Payment_model');
		if($this->Payment_model->check_payment($_POST)==0){
			$this->_assert_equals($this->Payment_model->check_payment($_POST),1);
		}else{
			$this->Payment_model->delete_payment($_POST);
			$this->_assert_equals($this->Payment_model->check_payment($_POST),0);
		}
		$_POST['student_number']='0000-00000';
		$_POST['choice']='00000';
		$_POST['type_hidden']='test_pay';
		$this->Payment_model->delete_payment($_POST);
	}
	
	/* For Report */
	function test_getCountAccomodationThatPass()
	{
		$this->message='Counts Accomodation';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_accomodation($_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->accomodation_count,1);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountClassificationThatPass()
	{
		$this->message='Counts Classification';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_classification($_POST['classification'],$_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->classification_count,1);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountCollegeThatPass()
	{
		$this->message='Counts College';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_college($_POST['college']);
		$row = $query->row();
		$this->_assert_equals($row->college_count,1);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountRegionalDistributionThatPass()
	{
		$this->message='Counts Regional Distribution';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='test_region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_regional_distribution($_POST['region'],$_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->regional_count,1);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountAccomodationThatFails()
	{
		$this->message='Counts Accomodation';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_accomodation($_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->accomodation_count,2);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountClassificationThatFails()
	{
		$this->message='Counts Classification';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_classification($_POST['classification'],$_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->classification_count,2);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountCollegeThatFails()
	{
		$this->message='Counts College';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_college($_POST['college']);
		$row = $query->row();
		$this->_assert_equals($row->college_count,2);
		$this->Resident_model->delete_resident($_POST);
	}
	
	function test_getCountRegionalDistributionThatFails()
	{
		$this->message='Counts Regional Distribution';
		$_POST['student_number']='0000-00000';
		$_POST['gender']='test_gender';
		$_POST['classification']='test_classification';
		$_POST['college']='test_college';
		$_POST['region']='test_region';
		$this->load->model('Resident_model');
		$this->Resident_model->add_resident($_POST);
		$this->load->model('Report_model');
		$query = $this->Report_model->get_count_regional_distribution($_POST['region'],$_POST['gender']);
		$row = $query->row();
		$this->_assert_equals($row->regional_count,2);
		$this->Resident_model->delete_resident($_POST);
	}
}
// End of file example_test.php */
// Location: ./system/application/controllers/test/example_test.php */
?>